package org.cafeanimal.sqlite;

import com.google.common.base.Optional;

/**
 * Field types for use with SQLite. Includes BOOLEAN although this
 * is handled as numeric by SQLite.
 *
 * @author michael
 */
public enum FieldType {
    INTEGER(Integer.class, "INTEGER"), 
    REAL(Double.class, "REAL"), 
    TEXT(String.class, "TEXT"), 
    BOOLEAN(Boolean.class, "BOOLEAN");
    
    
    private final Class<?> binding;
    private final String dbTypeName;

    private FieldType(Class<?> binding, String dbTypeName) {
        this.binding = binding;
        this.dbTypeName = dbTypeName;
    }

    public String getTypeName() {
        return dbTypeName;
    }

    public static Optional<FieldType> getFieldType(Class<?> clazz) {
        for (FieldType ft : FieldType.values()) {
            if (ft.binding.isAssignableFrom(clazz)) {
                return Optional.of(ft);
            }
        }
        return Optional.absent();
    }
    
}
